<?php
	require_once("../inc/function.php");
	
function GetCustomerKeywords()
{
	$conn = GetConnection();
    return $conn->query('SELECT * FROM Customer_keywords');
}

function GetCustomerKeyword($id)
{
	$conn = GetConnection();
    $sql = "SELECT * FROM Customer_keywords WHERE id=$id";
    $results = $conn->query($sql);    
    $row = $results->fetch_assoc();
    $conn->close();
    return $row;
}

function DeleteCustomerKeyword($id)
{
	$conn = GetConnection();
	$results = $conn->query("DELETE FROM Customer_keywords WHERE id=$id");
	header('Location: http://cs.newpaltz.edu/~N01852322/Final/CustomerKeywords/');
}
function NewCustomerKeyword($row)
{
	$customer_keyword = strip_tags($row['name']);
	if(strlen($customer_keyword)>0)	
	{
		$conn = GetConnection();
		$conn->query("INSERT INTO Customer_keywords Values(NULL, '$customer_keyword')");
		$conn->close();
	}
	else 
	{
		die("You need to enter a keyword value");	
	}
}
function SaveCustomerKeyword($row)
{
	$conn = GetConnection();
	$id = $row['id'];
	$value = strip_tags($row['name']);
	if(strlen($value)>0)
	{
		$conn->query("UPDATE Customer_keywords "
				.	"SET Value='$value'  "
				.	"WHERE id='$id' ");        
	}
	else 
	{
		header("Location: ../CustomerKeywords/edit.php");
	}		  
    $conn->close();		
    return $error == '' ? true : array('SQL error' => $error);			
}
?>